package site.wetsion.employ.server.controller;

import java.math.BigInteger;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;

import site.wetsion.employ.server.pojo.CampusNews;
import site.wetsion.employ.server.service.CampusService;
import site.wetsion.employ.server.util.Page;

@Controller
public class CampusController {
	
	@Autowired
	private CampusService campusService;
	
	@GetMapping("campus/list/{type}/{pageNum}")
	public String campusList(@PathVariable("type") int type, 
			@PathVariable("pageNum") int pageNum, Model model){
		Page page = new Page(pageNum, 15);
		List<CampusNews> newsList = campusService.getCampusNewsListByTypeAndPage(page, type);
		int count = campusService.getCountOfNewsByType(type);
		page.setTotalRecord(count);
		model.addAttribute("newsList", newsList);
		model.addAttribute("type", type);
		model.addAttribute("page", page);
		return "campus/list";
	}
	
	@GetMapping("campus/detail/{id}")
	public String campusDetail(@PathVariable BigInteger id, Model model){
		campusService.updateNewsSee(id);
		CampusNews campusNews = campusService.getCampusNewsById(id);
		model.addAttribute("news", campusNews);
		return "campus/detail";
	}

}
